//	Company:	HTHK
//	NAME:	    CategoryOptions.java
//	TITLE:	    The option of Project Category in Time Sheet System
//	FUNCTION:	The option of ProjectCategory associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------

package tss.options;

import java.sql.Connection;
import java.util.ArrayList;

import tss.projectcategory.ProjectCategoryBean;
import tss.projectcategory.ProjectCategoryProcess;

import com.ffpc.sql.ConnectionFactory;

/*public class CategoryOptions
  extends Options
{ 
  public CategoryOptions() {
      this.load();
  }

  protected ArrayList createOptions(Connection con)
    throws Exception
  {
      ArrayList options = new ArrayList();
      ProjectCategoryBean ProjectCategory = ProjectCategoryProcess.createBean();
      ProjectCategory.setProject_category_name("");
      ProjectCategoryBean[] ProjectCategorys = ProjectCategoryProcess.find(con,ProjectCategory);
      for (int i=0; i<ProjectCategorys.length; i++)
      {
          Options.Option option
          = new Options.Option( ProjectCategorys[i].getProject_category_name(),
                                ProjectCategorys[i].getProject_category_name()+"["+ProjectCategorys[i].getEffective_range_from()+"~]");
          options.add(i,option);
      }
      return options;
  }
}
*/
public class CategoryOptions  
{ 
	public String getDefualtOptions(String company,String category)
	 throws Exception
	{
		ConnectionFactory cf = null;
		StringBuffer htmlOptions = new StringBuffer();
		
		try {
		
	   cf = new ConnectionFactory("fasp_tss");
       Connection con = cf.getConnection();

      ArrayList options = new ArrayList();
      ProjectCategoryBean ProjectCategory = ProjectCategoryProcess.createBean();
      ProjectCategory.setCompany_code(company);
      ProjectCategoryBean[] ProjectCategorys = ProjectCategoryProcess.find(con,ProjectCategory);
      for (int i=0; i<ProjectCategorys.length; i++)
      {         
		  boolean selected = false;
          if(ProjectCategorys[i].getProject_category_name().equals(category))
         	  selected = true;               
          htmlOptions.append("   <option value=\"").append(ProjectCategorys[i].getProject_category_name()).append("\"").append(selected?" selected ":" ").append(" >").append(ProjectCategorys[i].getProject_category_name()).append("</option>\n");
      }
      
		} finally {
			cf.finalize();
		}
      
      return htmlOptions.toString();
	}
}